package cn.sumpu.app.coolsk.util;

import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class ExportWord {
	private final static Logger logger = LoggerFactory.getLogger(ExportWord.class);
	
	public static boolean writeWordFile(String path, String content) {
		try {
			ByteArrayInputStream bais = new ByteArrayInputStream(
					content.getBytes());
			POIFSFileSystem fs = new POIFSFileSystem();
			DirectoryEntry directory = fs.getRoot();
			directory.createDocument("WordDocument", bais);
			FileOutputStream ostream = new FileOutputStream(path);
			fs.writeFilesystem(ostream);
			bais.close();
			ostream.close();
			return true;

		} catch (IOException e) {
			if (logger.isErrorEnabled()) {
				logger.error("ExportWord error");
			}
			return false;
		}

	}

	public static void main(String[] args) {
		String content = "Form：贵州爽爽网络传媒股份有限公司 to：test酒店 sub：酒店预订\r\n\r\n"
				+ "***************订单号：orderId****************\r\n"
				+ "预定人：郭君军\r\n预定详情：预定详情订单状态：订单状态\r\n订单数量：123\r\n订单总额：1000\r\n入住时间：2012-07-19\r\n离店日期：2012-07-20\r\n联系电话：13816960375";
		boolean b = writeWordFile("/home/grieous/下载/poi导出/test.doc", content);
		System.out.println(b);

	}
}